<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 14-7-30
  Time: 下午1:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <%@include file="../../../includes/common.jsp" %>
    <title>
        题库列表
    </title>
</head>
<body>
<div id="mainContent" class="easyui-panel" data-options="fit:true" style="padding: 10px">
    <form class="form-inline" action="">

        <label for="title">题目</label>
        <input type="text" class="input-medium" name="title" id="title" value=""/>

        <label for="knowledgePoint">知识点</label>
        <input type="text" name="knowledgePoint" id="knowledgePoint" value="" class="input-medium"/>

        <label for="taskType">试题类型</label>
        <input type="text" name="taskType" id="taskType" value="" class="input-medium" flag="task_type"
               autocomplete="off"/>
        <input type="hidden" name="taskTypeId" id="taskTypeId" value="" autoHidden="autoHidden">

        <a class="btn btn-primary" onclick="query()">查询</a>
        <a class="btn btn-primary" onclick="addTask()">新增</a>
    </form>
    <table id="dataTable" style=""></table>
    <div id="dataEdit" closed="true" modal="true" style="overflow: hidden">
        <iframe style="width: 100%;height: 100%"
                id="contentFrame"
                name="contentFrame"
                marginheight="0"
                marginwidth="0"
                frameborder="0" src=""
                allowTransparency="true">
        </iframe>
    </div>
</div>
</body>
</html>

<script type="text/javascript">
    function query() {
        listOption.url = basePath + "task/library/listAllLibraryTask";
        listOption.data = "title=" + $("#title").val().trim() + "&knowledgePoint=" + $("#knowledgePoint").val() + "&taskType=" + $("#taskTypeId").val();
        listOption.pageNumber = 1;
        loadData(listOption);
    }

    function selectAll() {
        if ($("#checkAll").attr("checked") == "checked") {
            $("[name='auditCheckBox']").attr("checked", true);
        } else {
            $("[name='auditCheckBox']").attr("checked", false);
        }
    }

    function initDataGrid() {
        $('#dataTable').datagrid({
            title: "题库",
            pagination: true,
            fitColumns: true,
            columns: [
                [
                    {field: 'title', title: '题目', align: 'center', width: 200},
                    {field: 'showTaskType', title: '试题类型', align: 'center', width: 200},
                    {field: 'answer', title: '试题答案', align: 'center', width: 200},
                    {field: 'knowledgePoint', title: '知识点', align: 'center', width: 200},
                    {field: 'upDate', title: '上传时间', sortable: true, align: 'center', width: 200},
                    {field: 'operate', title: '操作', align: 'center', width: 200}
                ]
            ],
            sortName: "",
            sortOrder: "",
            onSortColumn: onSortColumn
        });
    }

    function onSortColumn(sortColumn, sortDirection) {
        switch (sortColumn) {
            case "upDate":
                sortColumn = "up_Date";
                break;
        }
        onSortColumnDefault(sortColumn, sortDirection);
    }

    function format(data) {
        data.resultList = queryFormat(data.resultList);
        return data;
    }

    function queryFormat(temp) {
        var rowDataList = [];
        for (var i in temp) {
            idBtn = "&nbsp;<input type='checkbox' name='auditCheckBox' id='" + temp[i].id + "' value='" + temp[i].id + "'\">&nbsp;";
            editBtn = "&nbsp;<a onclick='edit(" + temp[i].id + "," + temp[i].id + ")'>编辑</a>&nbsp;"
                    + "<a onclick='delTask(\"" + temp[i].id + "\")'>删除</a>&nbsp;&nbsp;";
            temp[i].id = idBtn;
            temp[i].operate = editBtn;
            rowDataList.push(temp[i]);
        }
        return rowDataList;
    }

    function edit(id) {
        var contentFrame = $("#contentFrame");
        var dataEdit = $("#dataEdit");
        contentFrame[0].contentWindow.document.write("");
        contentFrame.attr("src", basePath + "task/library/editLibraryTaskDo?id=" + id);
        dataEdit.dialog({
            title: '编辑',
            height: 400,
            width: 600
        });
        dataEdit.dialog('open');
    }

    function delTask(taskId) {
        $.messager.confirm("<spring:message code="prompt"/>", "<spring:message code="ensure"/><spring:message code="delete"/><spring:message code="questionMark"/>", function (r) {
            if (r) {
                $.ajax({
                    url: basePath + "task/library/deleteLibraryTask?id=" + taskId,
                    dataType: "json",
                    type: "DELETE",
                    success: function () {
                        $.messager.alert("<spring:message code="succeed"/>", "<spring:message code="delete"/><spring:message code="succeed"/>", "", function () {
                            query();
                        })
                    },
                    error: doError
                })
            }
        })
    }

    function addTask(){
        window.location.href = basePath + "task/library/addTaskDo";
    }

    $(function () {
        initDataGrid();
        query();
    })
</script>
